package ch.exploadingelephants.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import ch.exploadingelephants.graph.Token;

/**
 * @author Sandro De Zanet
 * 
 */
public abstract class MachineItem implements Serializable {

    public MachineItem() {
    }

    /**
     * @param resources
     * @return
     */
    public abstract List<Bitmap> getBitmaps(Resources resources);

    protected Bitmap loadBitmap(int resourceId, Resources resources) {
	return BitmapFactory.decodeResource(resources, resourceId);
    }

    /**
     * @return
     */
    public boolean isStart() {
	return false;
    }

    /**
     * @return
     */
    public abstract Token createGraphObject();

    /**
     * @return
     */
    public boolean isDeletable() {
	return true;
    }

    /**
     * @return
     */
    public abstract MachineItem copyItem();

    /**
     * @param resourceIDs
     * @param resources
     * @return
     */
    protected List<Bitmap> loadBitmaps(Integer resourceID, Resources resources) {
	List<Bitmap> result = new ArrayList<Bitmap>(1);
	result.add(loadBitmap(resourceID, resources));
	return result;
    }

    /**
     * @param resourceIDs
     * @param resources
     * @return
     */
    protected List<Bitmap> loadBitmaps(List<Integer> resourceIDs,
	    Resources resources) {
	List<Bitmap> result = new ArrayList<Bitmap>(resourceIDs.size());
	for (int id : resourceIDs) {
	    result.add(loadBitmap(id, resources));
	}
	return result;
    }
}
